package com.sdygmedia.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.sdygmedia.base.BaseDaoImpl;
import com.sdygmedia.dao.ArticleDao;
import com.sdygmedia.domain.Article;
import com.sdygmedia.domain.Category;
import com.sdygmedia.domain.CategoryChild;

@Repository
public class ArticleDaoImpl extends BaseDaoImpl<Article> implements ArticleDao  {

	@Override
	public List<Article> getByCategory(Category category) {
		// TODO Auto-generated method stub
		Query q = getSession().createQuery("from Article article where article.categoryChild.category.id='" + category.getId() + "' order by article.date desc");
		List<Article> articleList = q.list();
		
		return articleList;
	}

	@Override
	public List<Article> getByCategoryChild(CategoryChild categoryChild) {
		// TODO Auto-generated method stub
		Query q = getSession().createQuery("from Article article where article.categoryChild.id='" + categoryChild.getId() +"' order by article.date desc");
		List<Article> articleChildList = q.list();
		
		return articleChildList;
	}

	@Override
	public List getIndexImage() {
		// TODO Auto-generated method stub
		Query q = getSession().createQuery("from Article article where article.categoryChild.isImageList='true' order by article.date desc");
		q.setMaxResults(6);
		List<Article> articles = q.list();
		return articles;
	}

}
